package work;

public class Work8 {
	public static void main(String[] args) {
		String s = "zahdsab";
		int count = lengthOfLongestSubstring(s);
		System.out.println(count);
	
}
	public static int lengthOfLongestSubstring(String s) {

        if(s.length()==0||s.length()==1){
            return s.length();
        }

        String result="";
        int maxLength =0;

        for(int j=0;j<s.length();j++){
            for(int i=j;i<s.length();i++){
            if(!result.contains(String.valueOf(s.charAt(i))) ) {
                result=result + String.valueOf(s.charAt(i));
                if(result.length()>maxLength){
                    maxLength=result.length();
                }
            
            }else{
                if(result.length()>maxLength){
                    maxLength=result.length();
                }
                result ="";
                 result=result + String.valueOf(s.charAt(i));
            }
           
        }
          if(result.length()>maxLength){
                    maxLength=result.length();
           }
          result ="";
           }
          return maxLength;
    }

}
